<script type='text/javascript' src='${base}/dwr/engine.js'></script>
<script type='text/javascript' src='${base}/dwr/util.js'></script>
<script type='text/javascript' src='${base}/dwr/interface/backUserService.js'></script>
<script type="text/javascript">

	var flag=true;
	j(function(){
		j("#loginName").blur(function(){
			j("#loginName_error").hide();
			j("#loginName_success").hide();
			if(j(this).val().length==0){
				j("#loginName_error").show();
				j("#loginName_error_m").text("用户帐号不能为空");
				flag=false;
			}else{
				backUserService.findBackUserByLoginName(j.trim(j(this).val()),function(data){
					if(data==null){
						j("#loginName_success").show();
					}else{
						j("#loginName_error").show();
						j("#loginName_error_m").text("此帐号已存在");
						flag=false;
					}
				})
			}
		})
		
		j("#password1").blur(function(){
			j("#password1_error").hide();
			j("#password1_success").hide();
			if(j("#password1").val().length==0){
				j("#password1_error_m").text("密码不能为空")
				j("#password1_error").show();
				flag=false;
			}else{
				if(j("#password1").val().length<6 || j("#password1").val().length>16){
					j("#password1_error_m").text("密码长度为6~16位");
					j("#password1_error").show();
					flag=false;
				}else{
					j("#password1_success").show();
				}
			}
		});
		
		j("#password2").blur(function(){
			j("#password2_error").hide();
			j("#password2_success").hide();
			if(j("#password2").val().length==0){
				j("#password2_error").show();
				j("#password2_error_m").text("密码不能为空");
				flag=false;
			}else{
				if(j("#password2").val().length<6 || j("#password2").val().length>16){
					j("#password2_error_m").text("密码长度为6~16位");
					j("#password2_error").show();
					flag=false;
				}else{
					if(j("#password1").val()!= j("#password2").val()){
						j("#password2_error_m").text("两次输入的密码不相同");
						j("#password2_error").show();
						flag=false;
					}else{
						j("#password2_success").show();
					}
				}
			}
		});
		
		j("#nickname").blur(function(){
			j("#nickname_error").hide();
			j("#nickname_success").hide();
			if(j("#nickname").val().length==0){
				j("#nickname_error_m").text("用户昵称不能为空");
				j("#nickname_error").show();
				flag=false;
			}else{
				j("#nickname_success").show();
			}
		})
	
	})

	function checkForm(){
		var blog=true;
		j("form span[id$='_error']").hide();
		j("form span[id$='_success']").hide();
		if(j("#loginName").val().length==0){
			j("#loginName_error_m").text("用户帐号不能为空");
			j("#loginName_error").show();
			blog=false;
		}
		
		var regloginName =/[^\a-\z\A-\Z0-9\@\.\_]/;
		if(regloginName.test(j("#loginName").val())){
			j("#loginName_error_m").text("用户帐号格式不正确");
			j("#loginName_error").show();
			blog=false;
		}
		
		if(j("#password1").val().length<6 || j("#password1").val().length>16){
			j("#password1_error_m").text("密码长度为6~16位")
			j("#password1_error").show();
			blog=false;
		}
		
		if(j("#password2").val().length<6 || j("#password2").val().length>16){
			j("#password2_error_m").text("密码长度为6~16位")
			j("#password2_error").show();
			blog=false;
		}
		
		if(j("#password1").val()!= j("#password2").val()){
			j("#password2_error_m").text("两次密码输入不相同")
			j("#password2_error").show();
			blog=false;
		}
		
		if(j("#nickname").val().length==0){
			j("#nickname_error").show();
			j("#nickname_error_m").text("用户昵称不能为空")
			blog=false;
		}
		
		dwr.engine.setAsync(false);
		backUserService.findBackUserByLoginName(j.trim(j("#loginName").val()),function(data){
			if(data!=null){
				j("#loginName_error_m").text("此帐号已存在");
				j("#loginName_error").show();
				blog=false;
			}
		})
		dwr.engine.setAsync(true);
		
		if(blog==true){
			j("form span[id$='_success']").show();
			saveBackUserByDWR();
		}
	}
	
	function saveBackUserByDWR(){
		var callBack=function(o){
			parent.addNewUserSuccess(o,"新增");
			closerparent();
		}
		var newBackUser={
				"loginName":j.trim(j("#loginName").val()),
				"password":j.trim(j("#password2").val()),	
				"nickname":j.trim(j("#nickname").val())
			};
		backUserService.saveBackUser(newBackUser,callBack)
	}
	
	
	
	
	function clearForm(){
		j("#reset").click();
		j("form span[id$='_error']").hide();
		
	}
	
	function closerparent(){
	    parent.floatboxclose(false);
	}
</script>


<div class="container" id="cpcontainer">
<div class="close"></div>
<div class="itemtitle"><h3>新增用户信息<span id="post-form-loading"></span></h3></div>
<form >
<table border="0" class="tb tb2" >
	<tr>
		<td class=td21>
			用户编号：
		</td>
		<td id="storeNo">
			系统自动生成...
		</td>
	</tr>
	<tr>
		<td class=td21>
			用户账号：<br/><font color="red">(英文,数字,小数点,@,_)</font>
		</td>
		<td>
			<input type="text" id="loginName" size="25" value=""  maxlength="50" onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\@\.\_]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9\@\.\_]/g,'')" oncontextmenu = "value=value.replace(/[^\a-\z\A-\Z0-9\@\.\_]/g,'')"/><font color="red">*</font>
			<span id="loginName_error" style="color: red;display: none;">
				<img src="/cyMall/images/sign_warning.png"/><span id="loginName_error_m"></span>
			</span><img id="loginName_success" style="display: none" src="${base}/images/tonguo.png">
		</td>
	</tr>
	<tr>
		<td class=td21>
			用户密码：<br/><font color="red">(6-16位英文数字符号)</font>
		</td>
		<td>
			<input type="password" id="password1" size="25" value="" maxlength="16" /><font color="red">*</font>
			<span id="password1_error" style="color:red;display: none;">
				<img src="/cyMall/images/sign_warning.png"/><span id="password1_error_m"></span>
			</span><img id="password1_success" style="display: none" src="${base}/images/tonguo.png">
		</td>
	</tr>
	<tr>
		<td class=td21>
			确认用户密码：<br/>
		</td>
		<td>
			<input type="password" id="password2" size="25" value="" maxlength="16" /><font color="red">*</font>
			<span id="password2_error" style="color:red;display: none;">
				<img src="/cyMall/images/sign_warning.png"/><span id="password2_error_m"></span>
			</span><img id="password2_success" style="display: none" src="${base}/images/tonguo.png">
		</td>
	</tr>
	<tr>
		<td class=td21>
			用户昵称：
		</td>
		<td>
			<input type="text" id="nickname"  size="25" value="" maxlength="25" onkeyup="value=value.replace(/\s+/g,'')"/><font color="red">*</font>
			<span id="nickname_error" style="color:red;display: none;">
				<img src="/cyMall/images/sign_warning.png"/><span id="nickname_error_m"></span>
			</span><img id="nickname_success" style="display: none" src="${base}/images/tonguo.png">
		</td>
	</tr>
	<tr>
		<td colspan="3">
			<INPUT type="button"  value="     保存     " onclick ="checkForm()"/>&nbsp;&nbsp;
			<INPUT type="button"  value="     重置     " onclick ="clearForm()"/>&nbsp;&nbsp;
			<INPUT type="button"  value="     取消     " onclick ="closerparent()"/>
			<input type="reset" id="reset" style="display: none"> 
		</td>
	</tr>
</table>
</form>
</div>
